package com.huawei.appgallery.wlanapp.impl;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.wlanapp.ui.WlanAppListFragment;
import com.huawei.hms.support.api.entity.pay.HwPayConstant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import o.ccx;
import o.deg;
import o.dek;
import o.deo;
import o.dep;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONStringer;

public class WlanAppService extends Service {
    private static final String ˋ = WlanAppService.class.getSimpleName();
    private final o.eoa.c ˊ = new o.eoa.c(this) {
        final /* synthetic */ WlanAppService ॱ;

        {
            this.ॱ = r1;
        }

        public String ˋ(String str, String str2, String str3) throws RemoteException {
            Object obj = null;
            if (ccx.ॱ()) {
                JSONStringer jSONStringer = new JSONStringer();
                ArrayList arrayList = (ArrayList) WlanAppListFragment.ˊʻ();
                try {
                    jSONStringer.object();
                    Map hashMap = new HashMap();
                    if (this.ॱ.ˏ(str, str2, str3)) {
                        List<c> ˊ = this.ॱ.ˋ();
                        if (ˊ == null || ˊ.isEmpty()) {
                            jSONStringer.key("rtnCode").value("1");
                            hashMap.put("rtnCode", "1");
                        } else {
                            jSONStringer.key("rtnCode").value("0");
                            jSONStringer.key("downloadList");
                            jSONStringer.array();
                            JSONStringer jSONStringer2 = new JSONStringer();
                            jSONStringer2.object();
                            jSONStringer2.key("downloadList");
                            jSONStringer2.array();
                            for (c cVar : ˊ) {
                                for (int i = 0; i < arrayList.size(); i++) {
                                    if (cVar.ॱ.equals(arrayList.get(i))) {
                                        JSONStringer jSONStringer3 = new JSONStringer();
                                        jSONStringer3.object();
                                        jSONStringer3.key("packageName").value(cVar.ॱ);
                                        jSONStringer3.endObject();
                                        JSONObject jSONObject = new JSONObject(jSONStringer3.toString());
                                        jSONStringer.value(jSONObject);
                                        jSONStringer2.value(jSONObject);
                                    }
                                }
                            }
                            jSONStringer.endArray();
                            jSONStringer2.endArray();
                            jSONStringer2.endObject();
                            String string = new JSONObject(jSONStringer2.toString()).getString("downloadList");
                            hashMap.put("rtnCode", "0");
                            hashMap.put("downloadList", string);
                        }
                    } else {
                        jSONStringer.key("rtnCode").value("2");
                        hashMap.put("rtnCode", "2");
                    }
                    Object ˋ = dep.ˊ().ˋ();
                    if (!TextUtils.isEmpty(ˋ)) {
                        obj = deo.ॱ(hashMap, ˋ);
                    }
                    jSONStringer.key(HwPayConstant.KEY_SIGN).value(obj);
                    jSONStringer.endObject();
                } catch (JSONException e) {
                    deg.ˏ.ˊ(WlanAppService.ˋ, "getDownloadList(String timesecond, String packageName, String sign) " + e.toString());
                }
                return jSONStringer.toString();
            }
            deg.ˏ.ˏ(WlanAppService.ˋ, "getDownloadList blocked, not agree protocol");
            return null;
        }
    };

    static class c {
        String ॱ;

        private c() {
        }
    }

    public IBinder onBind(Intent intent) {
        return this.ˊ;
    }

    private List<c> ˋ() {
        List arrayList = new ArrayList();
        for (SessionDownloadTask sessionDownloadTask : dek.ˋ().ˏ()) {
            if (2 == sessionDownloadTask.ˈ()) {
                c cVar = new c();
                cVar.ॱ = sessionDownloadTask.ˊˊ();
                arrayList.add(cVar);
            }
        }
        return arrayList;
    }

    private boolean ˏ(String str, String str2, String str3) {
        if (TextUtils.isEmpty(str3)) {
            return false;
        }
        Object ˋ = dep.ˊ().ˋ();
        if (TextUtils.isEmpty(ˋ)) {
            return false;
        }
        Map hashMap = new HashMap();
        hashMap.put("ts", str);
        hashMap.put("packageName", str2);
        return str3.equals(deo.ॱ(hashMap, ˋ));
    }

    public void onCreate() {
        super.onCreate();
    }
}
